$(document).ready(function(){

	access_token = $.getCookie("access_token");
	var sortTime = "";

	var isShow = getQueryString(window.location.href,"isShow");

	var isLoad = 0;

	//展现与隐藏退款详情
	$.boundShowFunction = function(className,className2){
		$(className).click(function(){
			if($(className2).css('display') == "none"){
				$(className2).show();
				$(className+' .record-show').attr('src','/static/images/down-icon.png');
			}
			else{
				$(className2).hide();	
				$(className+' .record-show').attr('src','/static/images/up-icon.png');
			}
		})
	}


	//获取并展示提现数据
	$.loadMessage = function(){
		$.getJSON("/"+server+"/userMoneyHistoryGet?access_token="+access_token+"&type=2&sortTime="+sortTime+requestLast,function(json){
			sortTime = json.sortTime;
			if(json.result == 1){
				$('.loading-more').hide();
				for(var i=0;i<json.data.length;i++){
					var titleName = "record-title"+json.data[i].id;
					var contentName = "record-content"+json.data[i].id;
					var flowImage = "";
					var content = "";
					var titleType = "";
					var recordTitleStyleStr = "";
					var reserveTm = new Date(Date.parse("2016-01-01 00:00:00".replace(/-/g, "/")))
					var myDate = new Date(Date.parse(json.data[i].addTime.toString().replace(/-/g, "/")))
					var isOld = 0;

					if(reserveTm > myDate){
						isOld = 1;
					}

					if(json.data[i].status == 1 && isOld == 0){
						flowImage = "/static/images/pickup-flow-icon-2.png";

						content	= '<div class="flow flow1">'+
										'<p style="color:#00CEFC">来电正在处理</p>'+
										'<span>已将退款申请交至微信</span>'+
										'<br/>'+
										'<span>'+json.data[i].updateTime+'</span>'+
								  '</div>'+
								  '<div class="flow flow2">'+
										'<p>微信正在处理</p>'+
										'<span>您的资金转至微信处理</span>'+
								  '</div>'+
								  '<div class="flow flow3">'+
										'<p>已到账</p>'+
										'<span>微信将退款原路返回到你的支付账户中</span>'+
								  '</div>'	
						titleType = "正在处理";	
							
					}
					else if(json.data[i].status == 2  && isOld == 0){
						flowImage = "/static/images/pickup-flow-icon-3.png";

						content	= '<div class="flow flow1">'+
										'<p style="color:#00CEFC">来电正在处理</p>'+
										'<span>已将退款申请交至微信</span>'+
								  '</div>'+
								  '<div class="flow flow2">'+
										'<p  style="color:#00CEFC">微信正在处理</p>'+
										'<span>您的资金转至微信处理</span>'+
										'<br/>'+
										'<span>'+json.data[i].updateTime+'</span>'+										
								  '</div>'+
								  '<div class="flow flow3">'+
										'<p>已到账</p>'+
										'<span>微信将退款原路返回到你的支付账户中</span>'+
								  '</div>'	
						titleType = "正在处理";	
									
					}
					else if(json.data[i].status == 3 || isOld == 1){
						flowImage = "/static/images/pickup-flow-icon-4.png";

						content	= '<div class="flow flow1">'+
										'<p style="color:#00CEFC">来电正在处理</p>'+
										'<span>已将退款申请交至微信</span>'+
								  '</div>'+
								  '<div class="flow flow2">'+
										'<p style="color:#00CEFC">微信正在处理</p>'+
										'<span>您的资金转至微信处理</span>'+
								  '</div>'+
								  '<div class="flow flow3">'+
										'<p style="color:#00CEFC">已到账</p>'+
										'<span>微信将退款原路返回到你的支付账户中</span>'+
										'<br/>'+
										'<span>'+json.data[i].updateTime+'</span>'+										
								  '</div>'	
						titleType = "已完成";	
						recordTitleStyleStr = 'style="color:#E4E5E6"'	
					}

					var recordShow = 'style="display:none"';
					if(i == 0){
						if(isShow != null && isShow != 0){
							recordShow = 'style="display:block"';
							isShow = 0;
						}
					}

					if(isShow == null){
						if(json.data[i].status == 1 && isOld == 0){
							recordShow = 'style="display:block"';
						}
						else if(json.data[i].status == 2  && isOld == 0){
							recordShow = 'style="display:block"';
						}
					}


					$("body").append(			
							'<div class="record" >'+
								'<div class="record-title '+titleName+'" '+recordTitleStyleStr+'>'+
									'<span class="pickup-money">提现金额：'+(-(json.data[i].money))+'</span>'+
									'<div class="record-title-info">'+
										'<span class="record-time">'+json.data[i].addTime+'</span>'+
										'<span class="record-type">'+titleType+'</span>'+
									'</div>'+	
									'<img class="record-show" src="/static/images/up-icon.png">'+
								'</div>'+
								'<div class="record-content '+contentName+'" '+recordShow+'>'+
									'<img class="flow-icon" src="'+flowImage+'">'+
									content+
								'</div>'+
							'</div>'
						)	
					$.boundShowFunction('.'+titleName,'.'+contentName);			
					isLoad = 0;
				}
			}
			if(sortTime == 0){
				$("body").append(
					'<div class="no-data" style="text-align:center;font-size:1em">'+
						'没有更多了！'+
					'</div>'
				)
			}
		});	
	}

	$.loadMessage();

	$(window).scroll(function() {
		if(sortTime != 0 && isLoad == 0){
			isLoad = 1;
			if($(document).scrollTop() + $(window).height() >= $(document).height()){
				$('.loading-more').show();
				$.loadMessage();
			}
		}
	});

})